package com.tech.connect.huanzhewan;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckBox;

import com.ksy.common.utils.BaseAdapter;
import com.ksy.common.utils.BaseHolder;
import com.ksy.common.view.HLineDivider;
import com.tech.connect.R;
import com.tech.connect.fragment.BaseFragment;

import java.util.ArrayList;
import java.util.List;

public class HuanZheWanWanPinGuiFragment extends BaseFragment {


    private RecyclerView recycler;
    private List<String> allList = new ArrayList<>();
    private BaseAdapter<String, BaseHolder> adapter;

    @Override
    protected View onCreateView(LayoutInflater inflater) {
        View inflate = inflater.inflate(R.layout.fragment_huanzhewan_wanpingui, null);
        return (inflate);
    }

    @Override
    protected boolean isShowHeadBar() {
        return true;
    }

    @Override
    protected boolean isFullStateBar() {
        return true;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        getHeadBar().setLeftIcon(R.drawable.icon_back, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                activity.onBackPressed();
            }
        }).setTitle("玩品柜").setRightText("编辑", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                jump2Activity(HuanZheWanWanPinGuiActivity.class);
            }
        });
        initView(view);
        initAdapter();
    }


    private void initView(View view) {
        recycler = view.findViewById(R.id.recycler);
        recycler.setLayoutManager(new LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false));
        recycler.addItemDecoration(new HLineDivider());
    }

    private void initAdapter() {
        if (adapter == null) {
            adapter = new BaseAdapter<String, BaseHolder>(R.layout.item_huanzhewan_wanpingui, allList, 4) {
                @Override
                protected void convert(BaseHolder helper, int position) {
                    CheckBox checkBoxLeft = helper.getView(R.id.checkboxLeft);
                    CheckBox checkboxRight = helper.getView(R.id.checkboxRight);
                    checkBoxLeft.setVisibility(View.GONE);
                }
            };
            recycler.setAdapter(adapter);
        }
        adapter.notifyDataSetChanged();
    }

}
